<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文章管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>文章标题：</label>
                            <input type="text" name="articleTitle"/>
                        </li>
                        <li class="col-sm-4">
                            <label>所属栏目：</label>
                            <input id="frontMenuId" name="frontMenuId" type="hidden"/>
                            <div class="input-group">
                                <input class="form-control" type="text" onclick="selectFrontMenuTree()" id="treeName"
                                       readonly="true" required>
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </li>
                        <li>
                            <label>是否显示：</label>
                            <select name="isDisplay">
                                <option value="">所有</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()"  shiro:hasPermission="system:article:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
               shiro:hasPermission="system:article:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:article:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:article:export">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:article:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:article:remove')}]];
    var prefix = ctx + "system/article";
    var menu_prefix = ctx + "system/frontMenu"

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "文章管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'frontMenuName',
                    title: '所属栏目'
                },
                {
                    field: 'articleTitle',
                    title: '文章标题'
                },
                {
                    field: 'articleDescribe',
                    title: '简介'
                },
                {
                    field: 'articleLogo',
                    title: '缩略图',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value!= null) {
                            actions.push('<img style="height: 50px" src="'+value+'" />')
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'isDisplay',
                    title: '是否显示',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value === 1) {
                            actions.push('<span>是</span>')
                        }
                        if (value === 0) {
                            actions.push('<span>否</span>')
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'sort',
                    title: '排序'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function resetForm(){
        $("#frontMenuId").val("");
        $("#treeName").val("");
        $.form.reset()
    }

    /*菜单管理-新增-选择菜单树*/
    function selectFrontMenuTree() {
        var url = menu_prefix + "/getMenuTree";
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#frontMenuId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }
</script>
</body>
</html>